package com.neuedu.oasystem.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.neuedu.oasystem.dao.IMeetingPlaceDao;
import com.neuedu.oasystem.entity.MeetingPlace;
import com.neuedu.oasystem.util.DBHelper;

public class MeetingPlaceDaoImpl extends BaseDao implements IMeetingPlaceDao{

	@Override
	public boolean add(MeetingPlace param) {
		Connection connection = null;
		PreparedStatement statement = null;
		connection = getConnection();
		try {
			String sql = "insert into Meeting_Place(meeting_Place,galleyful,allocate_resource) values (?,?,?)";
			statement = connection.prepareStatement(sql);
			statement.setString(1, param.getMeetingPlace());
			statement.setInt(2, param.getGalleryful());
			statement.setString(3, param.getAllocateResourcess());
			int count = statement.executeUpdate();
			if (count==1) {
				return true;
			}
		} catch (SQLException e) {
			//throw new RuntimeException(e.getMessage());
		}finally {
			DBHelper.closeAll(null, statement, null);
		}
		
		return false;
	}

	@Override
	public boolean edit(MeetingPlace param) {
		Connection connection = null;
		PreparedStatement statement = null;
		connection = getConnection();
		try {
			String sql = "update Meeting_Place set galleyful=?,allocate_resource=? where meeting_Place=?";
			statement = connection.prepareStatement(sql);
			statement.setInt(1, param.getGalleryful());
			statement.setString(2, param.getAllocateResourcess());
			statement.setString(3, param.getMeetingPlace());
			int count = statement.executeUpdate();
			if (count==1) {
				return true;
			}
		} catch (SQLException e) {
			//throw new RuntimeException(e.getMessage());
		}finally {
			DBHelper.closeAll(null, statement, null);
		}
		
		return false;
	}

	@Override
	public boolean deleteById(int id) {
		return false;
	}

	@Override
	public MeetingPlace findById(int id) {
		return null;
	}

	@Override
	public List<MeetingPlace> findAll() {
		Connection connection = null;
		PreparedStatement statement = null;
		ResultSet resultSet = null;
		MeetingPlace meetingPlace2 ;
		List<MeetingPlace> list = new ArrayList<MeetingPlace>();
		connection = getConnection();
		try {
			String sql = " select meeting_Place,galleyful,allocate_resource from Meeting_Place";
			statement = connection.prepareStatement(sql);
			resultSet = statement.executeQuery();
			while (resultSet.next()) {
				String meetingPlace = resultSet.getString("meeting_Place");
				int galleryful = resultSet.getInt("galleyful");
				String allocateResources = resultSet.getString("allocate_Resource");
				meetingPlace2 = new MeetingPlace(meetingPlace, galleryful, allocateResources);
				list.add(meetingPlace2);
			}
		} catch (SQLException e) {
			//throw new RuntimeException(e.getMessage());
		}finally {
			
		}
		
		return list;
	}

	@Override
	public List<MeetingPlace> findByExample(MeetingPlace param) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<MeetingPlace> findByPager(int page, int size) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int deleteByIds(int[] ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int addAll(List<MeetingPlace> useparamrs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int editAll(List<MeetingPlace> param) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean delete(MeetingPlace param) {
		Connection connection = null;
		PreparedStatement statement = null;
		connection = getConnection();
		try {
			String sql = "delete from Meeting_Place where meeting_Place=?";
			statement = connection.prepareStatement(sql);
			statement.setString(1, param.getMeetingPlace());
			int count = statement.executeUpdate();
			if (count==1) {
				return true;
			}
		} catch (SQLException e) {
			//throw new RuntimeException(e.getMessage());
		}finally {
			DBHelper.closeAll(null, statement, null);
		}
		
		return false;	}


}
